import { apiClient } from './apiClient';

export interface DashboardStats {
  total_users: number;
  active_users: number;
  total_tasks: number;
  running_tasks: number;
  completed_tasks: number;
  failed_tasks: number;
  total_crawlers: number;
  running_crawlers: number;
  ai_models: number;
  active_models: number;
  data_volume: string;
  daily_requests: number;
  success_rate: number;
}

export interface SystemStats {
  cpu_usage: number;
  memory_usage: number;
  memory_total: number;
  memory_used: number;
  disk_usage: number;
  disk_total: number;
  disk_used: number;
  network_sent: number;
  network_recv: number;
  processes: number;
  uptime_days: number;
  uptime_hours: number;
  uptime_minutes: number;
}

export interface ActivityItem {
  id: number;
  type: string;
  title: string;
  description: string;
  timestamp: string;
  status: string;
  user_id: number;
}

export interface RecentActivity {
  total: number;
  activities: ActivityItem[];
}

export interface QuickStatsItem {
  tasks_completed: number;
  data_processed: string;
  api_calls: number;
  success_rate: number;
}

export interface QuickStats {
  today: QuickStatsItem;
  yesterday: QuickStatsItem;
  this_week: QuickStatsItem;
  this_month: QuickStatsItem;
}

export const dashboardService = {
  // 获取控制台统计数据
  async getDashboardStats(): Promise<DashboardStats> {
    return await apiClient.get<DashboardStats>('/dashboard/stats');
  },

  // 获取系统状态信息
  async getSystemStats(): Promise<SystemStats> {
    return await apiClient.get<SystemStats>('/dashboard/system');
  },

  // 获取最近活动记录
  async getRecentActivities(limit = 10): Promise<RecentActivity> {
    return await apiClient.get<RecentActivity>('/dashboard/activities', { limit });
  },

  // 获取快速统计信息
  async getQuickStats(): Promise<{ data: QuickStats }> {
    return await apiClient.get<{ data: QuickStats }>('/dashboard/quick-stats');
  }
};